package com.cn.icss.controller;

import com.alibaba.fastjson.JSONObject;
import com.cn.icss.service.IRewardService;
import com.cn.icss.service.impl.RewardServiceImpl;
import com.cn.icss.validator.RewardValidator;
import com.cn.icss.vo.GiftScoreRef;
import com.cn.icss.vo.TargetGiftRef;
import com.cn.icss.vo.common.ResponseCode;
import com.cn.icss.vo.common.ResponseResult;
import com.cn.icss.vo.common.ResponseStatus;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.ext.interceptor.GET;
import com.jfinal.ext.interceptor.POST;
import live.autu.plugin.jfinal.swagger.annotation.Api;
import live.autu.plugin.jfinal.swagger.annotation.ApiImplicitParam;
import live.autu.plugin.jfinal.swagger.annotation.ApiImplicitParams;
import live.autu.plugin.jfinal.swagger.annotation.ApiOperation;
import live.autu.plugin.jfinal.swagger.config.RequestMethod;
import org.apache.log4j.Logger;

import java.util.List;

/**
 * @中软华腾软件系统有限公司,未经授权不得擅自传播
 * @类描述:
 * @类名称:RewardController
 * @作者: Administrator
 * @编辑时间: 2020/05/13 15:39
 * @版本: 1.0
 */
@Api(description = "打赏接口",hidden = true)
public class RewardController extends Controller {

    Logger logger = Logger.getLogger(RewardController.class);

    @Inject(RewardServiceImpl.class)
    private IRewardService rewardService;


    @ApiOperation(methods= RequestMethod.GET)
    @Before(GET.class)
    public void findAllGift(){
        // 验证通过正常开发逻辑
        List<GiftScoreRef> gifts = rewardService.findAllGift();
        ResponseResult responseResult = ResponseResult.ok(gifts);
        renderJson(JSONObject.toJSONString(responseResult));
    }

    @ApiOperation(methods= RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name="targetId",required=true, description="打赏对象id(小视频id)"),
            @ApiImplicitParam(name="userId",required=true, description="打赏人Id"),
            @ApiImplicitParam(name="userName",required = true,description = "打赏人名称"),
            @ApiImplicitParam(name="giftId",required=true, description="打赏礼物Id"),
    })
    @Before({POST.class, RewardValidator.class})
    public void exceptional(){
        // 验证通过正常开发逻辑

        String targetId = getPara("targetId");
        String userId = getPara("userId");
        String giftId = getPara("giftId");
        String userName = super.getPara("userName");
        boolean result = rewardService.exceptional(targetId, userId,userName, giftId);
        ResponseResult responseResult = null;
        if(result){
            responseResult = ResponseResult.ok();
        }else{
            responseResult = ResponseResult.build(ResponseCode.Error, "保存打赏礼物失败", ResponseStatus.FAIL);
        }
        renderJson(JSONObject.toJSONString(responseResult));
    }


    @ApiOperation(methods= RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name="targetId",required=true, description="打赏对象id(小视频id)"),
    })
    @Before({POST.class, RewardValidator.class})
    public void findExceptionalGift(){
        String targetId = super.getPara("targetId");
        List<TargetGiftRef> exceptionalGift = rewardService.findExceptionalGift(targetId);
        ResponseResult responseResult = ResponseResult.ok(exceptionalGift);
        renderJson(responseResult);
//        renderJson(JSONObject.toJSONString(responseResult));
    }

}
